﻿Imports System.Data.OleDb

Public Class frmChiTietXuatNhap

    Private Sub frmChiTietXuatNhap_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Me.BackColor = Color.FromArgb(194, 217, 247)
            TabXuatNhap.SelectedTab = TabDonHangBan
            DonHangBan_Load()
            PhieuXuatKho_Load()
            PhieuNhapKho_Load()
        Catch ex As Exception
            ShowError(ex)
        End Try
    End Sub
#Region "Load Don Hang Ban"
    Protected Sub DonHangBan_Load()
        Try
            Dim dtDonHangBan As New DataTable
            Dim dbConn As New OleDb.OleDbConnection
            Dim dataAccess As New DataAccess
            Dim adapter As OleDb.OleDbDataAdapter
            Dim dbCommand As OleDb.OleDbCommand
            dataAccess.ConnectDatabase_DBAccess(dbConn)
            dbCommand = New OleDbCommand("spDonHangBan_MaSanPham_NgaySo", dbConn)
            dbCommand.CommandType = CommandType.StoredProcedure
            dbCommand.Parameters.Add("@MaSanPham", OleDbType.VarWChar).Value = lblMaSanPham.Text
            dbCommand.Parameters.Add("@Ngay_So", OleDbType.Integer).Value = lblNgaySo.Text
            adapter = New OleDb.OleDbDataAdapter(dbCommand)
            adapter.Fill(dtDonHangBan)
            dbConn.Close()
            'tính tổng
            Dim Tong As Single
            For Each dr As DataRow In dtDonHangBan.Rows
                Tong = Tong + Single.Parse(dr.Item("SoLuong"))
            Next
            lblTongDH.Text = Format(Tong, "N2")
            dgvDonHangBan.AutoGenerateColumns = False
            dgvDonHangBan.DataSource = dtDonHangBan
            
        Catch ex As Exception
            ShowError(ex)
        End Try
    End Sub
    Protected Sub PhieuXuatKho_Load()
        Try
            Dim dtDonHangBan As New DataTable
            Dim dbConn As New OleDb.OleDbConnection
            Dim dataAccess As New DataAccess
            Dim adapter As OleDb.OleDbDataAdapter
            Dim dbCommand As OleDb.OleDbCommand
            dataAccess.ConnectDatabase_DBAccess(dbConn)
            dbCommand = New OleDbCommand("spPhieuXuatKho_MaSanPham_NgaySo", dbConn)
            dbCommand.CommandType = CommandType.StoredProcedure
            dbCommand.Parameters.Add("@MaSanPham", OleDbType.VarWChar).Value = lblMaSanPham.Text
            dbCommand.Parameters.Add("@Ngay_So", OleDbType.Integer).Value = lblNgaySo.Text
            adapter = New OleDb.OleDbDataAdapter(dbCommand)
            adapter.Fill(dtDonHangBan)
            dbConn.Close()
            dgvPhieuXuatKho.AutoGenerateColumns = False
            dgvPhieuXuatKho.DataSource = dtDonHangBan
            Dim Tong As Single
            For Each dr As DataRow In dtDonHangBan.Rows
                Tong = Tong + Single.Parse(dr.Item("SoLuongTheoCTu"))
            Next
            lblTongXuatKho.Text = Format(Tong, "N2")
        Catch ex As Exception
            ShowError(ex)
        End Try
    End Sub
    Protected Sub PhieuNhapKho_Load()
        Try
            Dim dtDonHangBan As New DataTable
            Dim dbConn As New OleDb.OleDbConnection
            Dim dataAccess As New DataAccess
            Dim adapter As OleDb.OleDbDataAdapter
            Dim dbCommand As OleDb.OleDbCommand
            dataAccess.ConnectDatabase_DBAccess(dbConn)
            dbCommand = New OleDbCommand("spPhieuNHapKho_MaSanPham_NgaySo", dbConn)
            dbCommand.CommandType = CommandType.StoredProcedure
            dbCommand.Parameters.Add("@MaSanPham", OleDbType.VarWChar).Value = lblMaSanPham.Text
            dbCommand.Parameters.Add("@Ngay_So", OleDbType.Integer).Value = lblNgaySo.Text
            adapter = New OleDb.OleDbDataAdapter(dbCommand)
            adapter.Fill(dtDonHangBan)
            dbConn.Close()
            dgvPhieuNhapKho.AutoGenerateColumns = False
            dgvPhieuNhapKho.DataSource = dtDonHangBan
            Dim Tong As Single
            For Each dr As DataRow In dtDonHangBan.Rows
                Tong = Tong + Single.Parse(dr.Item("SoLuongTheoCTu"))
            Next
            lblTongNhap.Text = Format(Tong, "N2")
        Catch ex As Exception
            ShowError(ex)
        End Try
    End Sub
#End Region
End Class